      1  /**

      2     A tax return of a taxpayer in 2008.

      3  */

      4  public class TaxReturn

      5  {

      6     public static final int SINGLE = 1;

      7     public static final int MARRIED = 2;

      8

      9     private static final double RATE1 = 0.10;

     10     private static final double RATE2 = 0.25;

     11     private static final double RATE1_SINGLE_LIMIT = 32000;

     12     private static final double RATE1_MARRIED_LIMIT = 64000;

     13

     14     private double income;

     15     private int status;

     16

     17     /**

     18        Constructs a TaxReturn object for a given income and

     19        marital status.

     20        @param anIncome the taxpayer income

     21        @param aStatus either SINGLE or MARRIED

     22     */

     23     public TaxReturn(double anIncome, int aStatus)

     24     {

     25        income = anIncome;

     26        status = aStatus;

     27     }

     28

     29     public double getTax()

     30     {

     31        double tax1 = 0;

     32        double tax2 = 0;

     33

     34        if (status == SINGLE)

     35        {

     36           if (income <= RATE1_SINGLE_LIMIT)

     37           {

     38              tax1 = RATE1 * income;

     39           }

     40           else

     41           {

     42              tax1 = RATE1 * RATE1_SINGLE_LIMIT;

     43              tax2 = RATE2 * (income - RATE1_SINGLE_LIMIT);

     44           }

     45        }

     46        else

     47        {

     48           if (income <= RATE1_MARRIED_LIMIT)

     49           {

     50              tax1 = RATE1 * income;

     51           }

     52           else

     53           {

     54              tax1 = RATE1 * RATE1_MARRIED_LIMIT;

     55              tax2 = RATE2 * (income - RATE1_MARRIED_LIMIT);

     56           }

     57        }

     58

     59        return tax1 + tax2;

     60     }

     61  }